//
//  SEFollowedHospitalsCell.swift
//  SmartEyeForPatient
//
//  Created by QDSG on 2021/4/17.
//

import UIKit

protocol SEFollowedHospitalsCellDelegate: NSObjectProtocol {
    func followedHospitalsCellBtnAction(indexPath: IndexPath)
}

class SEFollowedHospitalsCell: UITableViewCell {

    private var indexPath = IndexPath(row: 0, section: 0)
    weak var delegate: SEFollowedHospitalsCellDelegate?

    override func awakeFromNib() {
        super.awakeFromNib()
        backgroundColor = .white
        contentView.backgroundColor = .white
    }

    func update(with viewModel: SEFollowedCellViewModel, indexPath: IndexPath) {
        self.indexPath = indexPath
        avatarImageView.kf.setImage(urlString: viewModel.model.imgUrl)
        nameLabel.text = viewModel.model.name
        gradeLabel.text = " \(viewModel.model.caption ?? "") "
        addressLabel.text = viewModel.model.description
    }
    
    @IBAction private func unfollowAction() {
        delegate?.followedHospitalsCellBtnAction(indexPath: indexPath)
    }

    @IBOutlet private weak var avatarImageView: UIImageView!
    @IBOutlet private weak var nameLabel: UILabel!
    @IBOutlet private weak var gradeLabel: UILabel! {
        didSet {
            gradeLabel.layer.cornerRadius = 2
            gradeLabel.layer.borderWidth = 1
            gradeLabel.layer.borderColor = UIColor(hex: "#FFB32D").cgColor
        }
    }
    @IBOutlet private weak var addressLabel: UILabel!
    @IBOutlet private weak var unfollowButton: UIButton! {
        didSet {
            unfollowButton.layer.cornerRadius = unfollowButton.height / 2
        }
    }
    
}
